export const setDisable = (level1: any, id: any) => {
  // 遍历数组，即遍历某一层节点
  for (let i = 0; i < level1.length; i++) {
    const node = level1[i];
    if (node.id === id) {
      // 将目标节点设置为disabled
      node.disabled = true;

      // 遍历所有子节点，将所有子节点全部都加上disabled
      const children = node.children;
      if (children) {
        for (let j = 0; j < children.length; j++) {
          setDisable(children, children[j].id);
        }
      }
    } else {
      // 如果当前节点不是目标节点，则到其子节点再找找看。
      const children = node.children;
      if (children) {
        setDisable(children, id);
      }
    }
  }
};

export const clearDisable = (level1: any) => {
  // 遍历数组，即遍历某一层节点
  for (let i = 0; i < level1.length; i++) {
    const node = level1[i];
    // 将目标节点设置为disabled
    node.disabled = false;

    // 遍历所有子节点，将所有子节点全部都加上disabled
    const children = node.children;
    if (children) {
      for (let j = 0; j < children.length; j++) {
        clearDisable(children);
      }
    }
  }
};

export const uuid = (len: number, radix = 62) => {
  const chars =
    "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
  const uuid = [];
  radix = radix || chars.length;

  for (let i = 0; i < len; i++) {
    uuid[i] = chars[0 | (Math.random() * radix)];
  }

  return uuid.join("");
};
